#include <algorithm>
#include <cstdint>
#include <cstdio>
#include <functional>
#include <iostream>
#include <istream>
using ll = int64_t;
#define printf

const ll maxn = 17;
ll isd=1;
ll n,m,x=1,y=1,ansx,ansy,ansn,a[maxn*maxn];

int main(){
    std::iostream::sync_with_stdio(false);
    std::cin.tie(nullptr);

    std::cin>>n>>m;
    for(ll i=1;i<=n*m;i++){
        std::cin>>a[i];
    }
    ansn=a[1];
    std::sort(a+1,a+1+n*m,std::greater<>());
    ll tot=1;
    while(y<=m){
        printf("x=%lld, y=%lld\n",x,y);
        if(x==n+1||x==0){
            y++;
            isd=isd*-1;
            x+=isd;
            continue;
        }
        ll tmp=a[tot++];
        printf("tmp=%lld\n",tmp);
        if(tmp==ansn){
            ansx=x,ansy=y,ansn=tmp;
            break;
        }
        x+=isd;
    }
    std::cout<<ansy<<" "<<ansx<<"\n";
}